package com.ygp.asyn.util;

import lombok.Getter;

import java.util.concurrent.*;

public class CommonPoolUtil {

    private static final int N_THREADS = 60;
    private static final int N_THREADS_OUT = 30;

    @Getter
    private static final ExecutorService OUT_EXEC = Executors.newFixedThreadPool(N_THREADS_OUT);

    @Getter
    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(
            Runtime.getRuntime().availableProcessors());

    /**
     *
     */
    @Getter
    private static final ExecutorService EXEC;


    static {
        EXEC = new ThreadPoolExecutor(N_THREADS, N_THREADS, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
    }

    public static void executeDB(Runnable runnable) {
        EXEC.execute(runnable);
    }

    public static void executeOut(Runnable runnable) {
        OUT_EXEC.execute(runnable);
    }

}
